package homework;

import javax.swing.*;
import java.io.*;

public class Test {
    public String b = null;

//拷贝文件
    public void cp() {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("D:/3.png");
            fos = new FileOutputStream("D:/4.png");
            int d = 0;
            while ((d = fis.read()) != -1) {
                fos.write(d);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //2. 输入一段字符串，将该字符串追加到指定文本文件中
    public void wr() {
        FileWriter fw = null;
        try {
//
            fw = new FileWriter("D:/1.txt", true);
            String str = null;

            str = JOptionPane.showInputDialog(null, "输入内容")+"\n";
            fw.write(str);
            fw.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static void main(String[] args) {
        Test t = new Test();
//        t.wr();
        t.cp();

    }
}
